using System;
using System.Runtime.InteropServices;
using System.Security;
namespace Net35.Xrm.Sdk.Discovery
{
	internal static class SdkUtilities
	{
		[SecuritySafeCritical]
		internal static string SecureStringToString(SecureString value)
		{
			if (value == null)
			{
				return null;
			}
			IntPtr intPtr = IntPtr.Zero;
			string result;
			try
			{
				intPtr = Marshal.SecureStringToBSTR(value);
				result = Marshal.PtrToStringUni(intPtr);
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.ZeroFreeBSTR(intPtr);
				}
			}
			return result;
		}
		internal static SecureString StringToSecureString(string value)
		{
			if (value == null)
			{
				return null;
			}
			SecureString secureString = new SecureString();
			for (int i = 0; i < value.Length; i++)
			{
				char c = value[i];
				secureString.AppendChar(c);
			}
			secureString.MakeReadOnly();
			return secureString;
		}
	}
}
